#include <stdio.h>
#include <string.h>
#include "wrap.h"
int main(int argc, char const *argv[])
{
        int fd = Socket(AF_INET,SOCK_DGRAM,0);
        // fd绑定本地的ip和端口
        struct sockaddr_in serv;
        memset(&serv,0,sizeof(serv));
        serv.sin_family = AF_INET;
        serv.sin_port = htons(8888);
        serv.sin_addr.s_addr = htonl(INADDR_ANY);
        Bind(fd,(struct sockaddr *)&serv,sizeof(serv));

        //通讯
        struct sockaddr_in client;
        socklen_t client_len = sizeof(client);
        char buf[1024] = {0};
        while (1){
                int recvlen = recvfrom(fd,buf,sizeof(buf),0,(struct sockaddr*)&client,&client_len);
                if(recvlen == -1){
                        perr_exit("recvfrom error\n");
                }
                printAddr("New Client", &client);
                printf("recv buf:%s\n",buf);

                //给客户端发送数据
                sendto(fd,buf,strlen(buf)+1,0,(struct sockaddr*)&client,sizeof(client));
        }
        Close(fd);
        return 0;
}
